import { PostCaseCommentReply, SetTaskScore } from "~/api";

export const useContent = (props, emits) => {
    const comment = ref("");
    const isBtnLoading = ref(false);
    const isShow = ref(false);
    const onSelectEmoji = (name) => {
        comment.value += `[${name}]`;
    };

    const onSend = async () => {
        if (!comment.value.trim()) {
            Message().warning("请输入评论内容");
            return;
        }
        const res = await PostCaseCommentReply({
            comment: comment.value,
            comment_id: props.commentId,
            examcase_id: props.examcaseId,
            to_uid: props.toUid,
        });

        if (res.code == 200) {
            SetTaskScore({
                code: 1016,
                _id: props.examcaseId,
            });
            isShow.value = false;
            emits("success");
        } else {
            Message().warning(res.msg);
        }
    };

    const onReply = () => {
        comment.value = "";
        isShow.value = !isShow.value;
    };

    return {
        isBtnLoading,
        isShow,
        comment,
        onSelectEmoji,
        onSend,
        onReply,
    };
};
